package restaurant.servlet;

import java.sql.SQLException;
import java.util.List;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import restaurant.pojo.Board;
import restaurant.pojo.FoodsType;
import restaurant.service.CuisineService;
import restaurant.service.impl.CuisineServiceImpl;
import restaurant.utils.BaseServlet;

/**
 * Servlet implementation class BusinessServlet
 */
@WebServlet("/restaurant/detail/BaseCuisineServlet")
public class BaseCuisineServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
	private CuisineService service = new CuisineServiceImpl();
	public String showCuisine(HttpServletRequest req,HttpServletResponse resp) {
		
//		System.out.println("展示菜系");
		try {
			List<FoodsType> cuisine = service.showCuisine();
			req.setAttribute("datas", cuisine);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "cuisineList.jsp";
	}
	public String addCuisine(HttpServletRequest req,HttpServletResponse resp) {
		String type = req.getParameter("type");
		try {
			service.addCuisine(type);			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "BaseCuisineServlet?action=showCuisine";
	}
	public String delCuisine(HttpServletRequest req,HttpServletResponse resp) {
		String id = req.getParameter("id");
		try {
			service.deleteCuisine(id);
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return "BaseCuisineServlet?action=showCuisine";
	}
	public String updateCuisine(HttpServletRequest req,HttpServletResponse resp) {
		String type = req.getParameter("type");
		String id = (String)req.getParameter("id");
		try {
			service.updateCuisine(type, id);
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "BaseCuisineServlet?action=showCuisine";
	}
	public String findCuisine(HttpServletRequest req,HttpServletResponse resp) {
		String param = req.getParameter("keyword");
		try {
			List<FoodsType> cuisine = service.findCuisine(param);
			req.setAttribute("datas", cuisine);
		} catch (SQLException e) {
			
			e.printStackTrace();
		}
		return "cuisineList.jsp";
	}
}
